<?php
require_once(APPPATH."models/base.php");

class template_model extends base_model
{	
	// 非数据库类型的MODEL
	function __construct()
	{
		parent::__construct("normal");
	} 
}

class template_manager extends base_manager 
{
	public function get($name)
	{
		return "";
	}

	public function get_list($where = Array()) 
	{
		$query_result = new stdClass();
		$page = array_remove($where,'page');$page == null && $page = 1 ;
		$page_size = array_remove($where,'page_size');
		
		$ci = &get_instance();
		$ci->load->helper('directory'); 
		$dmap = directory_map('application/views',2);
		//print_r($dmap);exit;
		$templates = Array() ; 
		foreach($dmap as $name =>$value)
		{
			if(is_array($value))
			{
				$file_name = APPPATH.'views/'.$name."/admin_helper.php";
				// echo $file_name;
				if(file_exists($file_name))
				{
					require_once APPPATH.'views/'.$name."/admin_helper.php";
					$template = $tpl_info;
					$template->name = $name;
					$templates[] = $template; 
				}
				//file_exists($filename)
			}
		}
		$query_result->record_count = sizeof($templates);
		if($page_size != null)
		{
			$begin_index = ($page-1)*$page_size;
			$query_result->page_count = intval($query_result->record_count/$page_size)-1;
			$new_tpls = Array();
			$index = 0;
			foreach ($templates as $template)
			{
				if($index >= $begin_index && $index < $begin_index + $page_size)
				{
					$new_tpls[] = $template;
				}
			}
			$templates = $new_tpls;
		}
		
		$this->query_result = $query_result;
		return $this->convert_list(
				$templates
		);
	} 
}

?>